<?php $sN = "Content"; ?>
<style type="text/css">
    #more-image input{
        display: inline;
        margin: 5px 0;
    }
</style>
<script type="text/javascript">
    var text = '<?php echo $this->Form->input('more_image', array(
                                                        'label'     => false,
                                                        'name'      =>'data[Content][image][]',
                                                        'type'      => 'file',
                                                        'id'        =>'',
                                                        'div'       => false,
                                                        'class'     => 'inp-form med')
                                                    ); 
                                            ?>';
    function add_more(){
        $('#more-image').append(text);
        return false;
    }
    function delete_image(id){
        if(confirm("Are you sure to delete this image ?")){
            $.get('<?php echo $this->Html->url(array('controller'=>'users','action'=>'content_delete_image')) ?>/'+id, function(data){
                if(data=='true'){
                    $('#product-table tr#'+id).fadeOut('slow', function(){
                       $(this).remove(); 
                    });
                }
            });
        }
        return false;
    }
</script>
<div id="content">
    <div id="page-heading"><h1>Images for <?=$content['Content']['type']?></h1></div>
    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
        <tr>
            <th rowspan="3" class="sized">
                 <?php echo $this->Html->image('../images/shared/side_shadowleft.jpg', array('alt' => '', 'width' => '20', 'height' => '300')); ?>
            </th>
            <th class="topleft"></th>
            <td id="tbl-border-top">&nbsp;</td>
            <th class="topright"></th>
            <th rowspan="3" class="sized">
                <?php echo $this->Html->image('../images/shared/side_shadowright.jpg', array('alt' => '', 'width' => '20', 'height' => '300')); ?>
             </th>
        </tr>
        <tr>
            <td id="tbl-border-left"></td>
            <td>
                <div id="content-table-inner">
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr valign="top">
                            <td>
                                <?php echo $this->Form->create("$sN", array('url'=>array('controller'=>'users','action' => 'content_images'), 'class' => 'form', 'type' => 'file')); ?>
                                <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                <?php
                                    echo $this->Session->flash();
                                    echo $this->Form->input('id');
                                ?>
                                    <tr>
                                        <th valign="top">Image</th>
                                        <td  width="230"id="more-image">
                                            <?php
                                                echo $this->Form->input('more_image', array(
                                                        'label'     => false,
                                                        'id'        =>'',
                                                        'name'      =>'data[Content][image][]',
                                                        'type'      => 'file',
                                                        'div'       => false,
                                                        'class'     => 'inp-form med')
                                                    ); 
                                            ?>
                                        </td>
                                        <td><a class="button" href="<?php echo $this->Html->url(array('action'=>'content_images',$this->data['Content']['id'])) ?>" onclick="return add_more()">Add more</a></td>
                                    </tr>
                                    <tr>
                                        <th>&nbsp;</th>
                                        <td valign="top">
                                            <?php echo $this->Form->submit('Save', array('div'=>false,'class' => 'submit-button')); ?>
                                            <?php echo $this->Html->link('Cancel', array('controller' => "users", 'action' => 'content_edit', $this->data['Content']['id']), array('class' => 'cancel-button')); ?>
                                        </td>
                                        <td></td>
                                    </tr>
                                </table>
                                <?php echo $this->Form->end();?>    
                                
                                <table border="0" width="50%" cellpadding="0" cellspacing="0" id="product-table">
                                    <tr>
                                        <th class="table-header-repeat line-left">
                                           Image
                                        </th>
                                        <th width="100" class="table-header-repeat line-left">
                                           Action
                                        </th>
                                    </tr>
                                <?php 
                                    $alt = 0;
                                    foreach($images as $value): 
                                        $alt_row = $alt % 2;
                                        $alt_rows = ($alt_row == 1)? 'alternate-row': '';
                                ?>
                                    <tr id="<?=$value["ContentImage"]['id']?>" class="<?php echo $alt_rows; ?>">
                                        <td valign="top">
                                            <?php echo $this->Html->image("contents/thumb/{$value["ContentImage"]['image']}") ?>
                                        </td>
                                        <td class="options-width">
                                        <?php 
                                            echo $this->Html->link(' ', "#", array('onclick'=>"return delete_image('{$value["ContentImage"]['id']}')",'title' => "Delete", "class" => "icon-2 info-tooltip"));
                                        ?> 
                                        </td>
                                    </tr>
                                <?php
                                    $alt++;
                                    endforeach; 
                                ?>
                                </table>
                                
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                               <?php echo $this->Html->image('../images/shared/blank.gif', array('alt' => 'blank', 'width' => '695', 'height' => '1')); ?>
                            </td>
                            <td></td>
                        </tr>
                    </table>
                    <div class="clear"></div>
                </div>
            </td>
            <td id="tbl-border-right"></td>
        </tr>
        <tr>
            <th class="sized bottomleft"></th>
            <td id="tbl-border-bottom">&nbsp;</td>
            <th class="sized bottomright"></th>
        </tr>
    </table>
    <div class="clear">&nbsp;</div>
</div>
